//
//  ActivityCell.m
//  shise
//
//  Created by 毛志鹏 on 14/12/17.
//  Copyright (c) 2014年 MZP. All rights reserved.
//

#import "ActivityCell.h"
#import "UIImageView+WebCache.h"
@implementation ActivityCell

-(void)dealloc
{
    [_activity release];
    [_actImageView release];
    [_actTitle release];
    [_desc release];
    [_actImageButton release];
    [_mohu release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.actImageView = [[UIImageView alloc] init];
        self.actImageView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.actImageView];
        [_actImageView release];
        
        self.actImageButton = [UIButton buttonWithType:UIButtonTypeSystem];
        self.actImageButton.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.actImageButton];
        
        self.mohu = [[UIView alloc] init];
        self.mohu.backgroundColor = [UIColor colorWithRed:54/255.0 green:54/255.0 blue:54/255.0 alpha:0.3];
        [self.actImageView addSubview:self.mohu];
        [_mohu release];
        
        self.actTitle = [[UILabel alloc] init];
        self.actTitle.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.actTitle];
        [_actTitle release];
        
        self.desc = [[UILabel alloc] init];
        self.desc.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.desc];
        [_desc release];
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    // 上面初始化, 这个方法中布局
    // 上面的设置frame 就不需要了, 可以根据cell的高度设置子视图的样式
    _actTitle.frame = CGRectMake(0, 60, self.contentView.frame.size.width, 30);
    _actTitle.textAlignment = NSTextAlignmentCenter;
    _actTitle.textColor = [UIColor whiteColor];
    _actTitle.font = [UIFont boldSystemFontOfSize:22];
    
    
//    CGPoint temp = self.contentView.center;
//    NSLog(@"%f   %f", temp.x, temp.y);
//    temp.y += 20;
//    _desc.center = temp;
    _desc.frame = CGRectMake(self.contentView.frame.size.width / 2 - 50, 100, 100, 20);
    _desc.textAlignment = NSTextAlignmentCenter;
    _desc.textColor = [UIColor blackColor];
    _desc.alpha = 0.6;
//    _desc.layer.cornerRadius = 10;
    _desc.font = [UIFont boldSystemFontOfSize:14];
    
    _mohu.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    
    _actImageView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    
    _actImageButton.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    
}

// 重写Activity 的setter方法
-(void)setActivity:(Activity *)activity
{
    if (_activity != activity) {
        [_activity release];
        _activity = [activity retain];
    }
    [_actImageView setImageWithURL:[NSURL URLWithString:_activity.url]];
    self.actTitle.text = activity.title;
    self.desc.text = activity.desc;
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
